package org.rich.charlesmurphy.ui.renderers;

import java.awt.Color;
import java.awt.Component;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import org.ddevil.data.Data;
import org.rich.charlesmurphy.model.StatusCode;
import org.rich.charlesmurphy.ui.Colors;
import org.windowkit.toolkit.widget.table.RecordTableModel;
import org.windowkit.toolkit.widget.table.render.AbstractBackgroundRenderer;

/**
 * Renders bg color based on HTTP response status.
 * @author Rich
 */
public class StatusRenderer extends AbstractBackgroundRenderer {

	private static final Map<StatusCode, Color> colorMap;

	static {
		colorMap = new HashMap<StatusCode, Color>(3);
		colorMap.put(StatusCode.CACHED, Colors.CACHED);
		colorMap.put(StatusCode.NOT_FOUND, Colors.NOT_FOUND); //redish
		colorMap.put(StatusCode.SUCCSSS, Colors.SUCCSSS); //greenish
	}

	/**
	 *
	 */
	public StatusRenderer() {
		super();
	}

	/**
	 * @param decorateMe
	 */
	public StatusRenderer(TableCellRenderer decorateMe) {
		super(decorateMe);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected Color getColor(Component c, Data d, RecordTableModel model,
			JTable table, Object value, CellInfo info) {
		StatusCode status = StatusCode.fromCode(value.toString());
		return colorMap.get(status);
	}

}
